<template>
  <div>
    <TopFilter
      :list="topFilterList"
      :cols="3"
      @filterChange="changeHandle"
    ></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => this.columns = columns"
      :selectionType="'single'"
    >

    </FilterTable>
    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <el-button @click="closeDrawer(2)" type="primary" :disabled='isOpen'>确 定</el-button>
    </div>
  </div>
</template>
<script>
import {dealerList} from '@/api/omSale/OrderManagement/PickAddress/index.js'
import { dictionary } from '@/utils/dictMixin';
import { getRegion} from '@/api/cms-common/dealerdata/index';
import { dealerCommon } from '@/api/cms-api/origin/commonDealerType'; //经销商类型工具类

export default {
  data(){
    return{
      topFilterList:this.createdFrom(),
      columns:this.createdTable(),
     fetchParams: {
        status:10031001
      },
      appId:'beijing',
      fetchApi:dealerList,
      selectList:[],
      isOpen:true,
    }
  },
   mixins: [dictionary,dealerCommon],
    mounted() {
   
      //初始化事业部下拉数据
    this.getDeptList();
     

  },
  methods:{
      async getDeptList(){
      let res=await getRegion({orgType:15061005})
      let arr=res.data.map(x=>({text:x.orgName,value:x.orgId}))
      this.topFilterList.find(x=>x.fieldName=='deptId').itemList=arr;
    },
    createdFrom(){
      return [
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'dealerCode',
          placeholder: '请选择',
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          placeholder: '请选择',
        },
          
 {
          type: 'INPUT',
          label: '经销商简称',
          fieldName: 'dealerShortName',
          initialValue: '',
        
        },
      { 
              type: 'SELECT',  
              label: '渠道类型',  
              fieldName: 'dealerType',  
              placeholder: '请选择', 
            
               itemList:this.getOriginInfoDealerType(),
            },
          {
          type: 'SELECT',
          label: '事业部',
          fieldName: 'deptId',
          placeholder: '请选择',
          itemList:[]
        },
          {
            type: 'SELECT',
            label: '启用标记',
            fieldName: 'status',
            placeholder: '请选择',
             initialValue: 10031001,
            itemList: this.createDictList('1003'),
            }
      ]
    },
    createdTable(){
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '公司名称',
          dataIndex: 'dealerName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '经销商代码',
          dataIndex: 'dealerCode',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '经销商简称',
          dataIndex: 'dealerShortname',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '经销商类型',
          dataIndex: 'dealerType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('2538'),
          render: (p) => {
            return <span >{this.createDictText(p.row.dealerType, '2538')}</span>;
          },
        },
        {
          title: '经销商级别',
          dataIndex: 'shopLevel',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('2540'),
          render: (p) => {
            return <span >{this.createDictText(p.row.shopLevel, '2540')}</span>;
          },
        },
        {
          title: '事业部',
          dataIndex: 'deptName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '省份',
          dataIndex: 'provinceName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '城市',
          dataIndex: 'cityName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '县区',
          dataIndex: 'districtName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
      ]
    },
    changeHandle(val){
      this.isOpen=true;
      this.fetchParams=Object.assign({},this.fetchParams,val)
    },
    closeDrawer(type){
      if(type==1){
        this.$emit('close')
      }else{
        let json=this.selectList[0]
        this.$emit('close',json)
      }
    },
    selectChangeHandle(val){
      if(val.length>0){
        this.selectList=val;
        this.isOpen=false;
      }else{
        this.isOpen=true;
        this.selectList=[]
      }

    }
  },

}
</script>
